package com.caine.io;

import java.nio.IntBuffer;

/**
 * @Author: CaineZhu
 * @Description:
 * @Date: Created in 10:05 2020/11/3
 * @Modified By:
 */
public class BufferTest{
    public static void main(String[] args) throws InterruptedException {
        IntBuffer buff = IntBuffer.allocate(5);

        for(int i = 0;i<3;i++){
            buff.put(i);
        }

        buff.flip();
        while (buff.hasRemaining()){
            System.out.println(buff.get()+" ");
        }
        System.out.println("=============================");
        buff.flip();
        // 此处会报错 存入的position位置超过limit
        for(int i = buff.position();i<buff.capacity();i++){
            System.out.println("p"+i);
            buff.put(i);
        }

        buff.flip();
        while (buff.hasRemaining()){
            System.out.println(buff.get()+" ");
        }

    }
}
